---
title: "Populism in Gov v Opposition"
---

# Shaping GPS (Global Party Survey)

```{r, warning=F, message=F}
library(here)
library(tidyverse)
library(readxl)
library(ggpubr)
library(ggsci)
library(marginaleffects)
library(sandwich)

#Read Global Parties Data
gps <- read_excel(here("data/gps_by_party_V2_Apr_2020.xlsx"))

#Grab Latam Countries
gps_slim <- gps %>% 
  filter(Region == 2) 

# Countries to drop 
drop <- c("TTO", "SUR", "GUY", "CUB", "BRB", "HTI", "JAM")
gps_slim <- gps_slim %>% 
  filter(!(ISO %in% drop))

# Parties in government
winners_lapop <-  read_csv(here("data/lapop_winners.csv"), na = "NA")

# Code Government Parties in 2018
#Note: Honduras is not covered in GPS due to lack of response 
gov_party <- c("ARG_ PRO-UCR", "BOL_ MAS", "BRA_ PSL",  "CHL_ CV", "COL_ PCD",
                 "CRI_ PAC", "DOM_ PLD", "ECU_ PAIS",  "GTM_ FCN", "MEX_ MORENA",
                 "NIC_ FSLN", "PAN_ PP", "PER_ PKK", "PRY_ ANR", "SLV_ FMLN",
                 "URY_ FA", "VEN_ PSUV/GPP")


# Dummy for winning parties
gps_slim <- gps_slim %>% 
  mutate(in_gov = case_match(CPARTYABB, 
   gov_party ~ "Incumbent Party",
   .default = "Non-Inumbent Parties"
  ))

# Select some vars
gps_slim <- gps_slim %>% 
    select(ISO, Country, in_gov, Partyname, 
           Partyabb, V8_Scale, PartyPerVote)


# Populism by in-government or out of government
mean_populism <- gps_slim %>% 
  group_by(ISO, in_gov) %>% 
  summarise(discourse = mean(na.omit(V8_Scale))) %>% 
  na.omit()

# Vote Weighted Discourse 
mean_populism_weighted <- gps_slim %>% 
  na.omit() %>% 
  group_by(ISO, in_gov) %>% 
  summarise(discourse =  weighted.mean(V8_Scale,  PartyPerVote))
```

# Plot Populism in Gov v Opposition 

```{r}
# Plot mean populism 
mean_populism$in_gov <- factor(mean_populism$in_gov, 
                               levels = c("Incumbent Party", "Non-Inumbent Parties"))

mean_populism$ISO <- fct_reorder(mean_populism$ISO, mean_populism$discourse)

means <- ggplot(mean_populism, aes(x = ISO, y = discourse, fill = in_gov)) +
  geom_bar(stat = "identity", 
           position = position_dodge()) +
  labs(x = "Country", y = "Populist Rhetoric") +
  scale_fill_grey() +
  theme_pubclean() +
  theme(legend.title = element_blank()) 

# Plot populism weighted by votes 
mean_populism_weighted$in_gov <- factor(mean_populism_weighted$in_gov,
                                        levels = c("Incumbent Party", "Non-Inumbent Parties"))
mean_populism_weighted <- na.omit(mean_populism_weighted) 
mean_populism_weighted$ISO <- fct_reorder(mean_populism_weighted$ISO, mean_populism_weighted$discourse)

weighted_means <- ggplot(mean_populism_weighted, aes(x = ISO, y = discourse, fill = in_gov)) +
  geom_bar(stat = "identity", 
           position = position_dodge()) +
  theme_minimal() +
  labs(x = "Country", y = "Populist Rhetoric") +
  scale_fill_grey() +
  theme_pubclean() +
  theme(legend.title = element_blank()) 

pop_plot <- ggarrange(means, weighted_means, common.legend = T, nrow = 2,
                      legend = "bottom", labels = c("A", "B"))

pop_plot


# Save to dropbox
ggsave(
  here("figures/pop_gov_opp.pdf"), 
  height = 6, 
  width = 8)


```

# Major Populist Opposition Parties

```{r}

gps_slim %>% 
  filter(V8_Scale > 7 & 
           in_gov == "Non-Inumbent Parties" &
           PartyPerVote > 10)


op_countries <-  gps_slim %>% 
  filter(V8_Scale > 7 & 
           in_gov == "Non-Inumbent Parties" &
           PartyPerVote > 10)


```

# Populist Opposition in LAPOP Data 

```{r}

lapop <- load(here("data/lapop_10_18.Rdata"))

# Select 2018 data
lapop_18 <- lapop.cleaned %>% 
  filter(wave == 2018)


# Just countries with major populist opposition 
lapop_18 <- lapop_18 %>% 
  filter(iso3c %in% op_countries$ISO)

# Countries in the dataset 
unique(lapop_18$iso3c) %>% 
  droplevels() 

# Populist Opposition -------------------------------------#
# ARG - Frente para la Victoria - 1702
# CHI - FA - 1303
# CRI - PRN - 602
# ECU - PSC - 903
# GTM - LIDER - 203
# PER - Fuerza Popular - 1102
#----------------------------------------------------------#

# Incumbent parties 
inc <- c(1701, 601, 1301, 1101, 201)

# Populist Opposition parties 
pop <- c(1702, 602, 1303, 1102, 203)


# Code Populist Opposition, Non-Supporters, and Incumbents 
lapop_18 <- lapop_18 %>% 
  mutate(
    vote = case_match(vb3n_18,
                      inc ~ "Incumbent Party",
                      pop ~ "Populist Opposition", 
                      c(0, 97) ~ NA_character_,
                      .default = "Non-Populist Opposition")
  )

```

# Model Support for Closing Congress or Court

```{r}


lapop_18 <- lapop_18 %>%
  mutate(across(c(female, rural, non_voter), factor))

m1_cong <- glm(close.cong ~ dem.best + sat_dem + edu + wealth + rural + wealth + female +
                        trust.people + neigh.safe + econ.eval + non_voter +  vote,
                      data = lapop_18, family = binomial(link = "logit"))


m1_court <- glm(close.court ~ dem.best + sat_dem + edu + wealth + rural + wealth + female +
                        trust.people + neigh.safe + econ.eval + non_voter + vote,  
                      data = lapop_18, family = binomial(link = "logit"))


levs <- c("Incumbent Party", "Non-Populist Opposition", "Populist Opposition")

# Predictions with Country Clustered SEs
cong_preds <- predictions(m1_cong, newdata = datagrid(vote = levs), vcov = ~country)
court_preds <- predictions(m1_court, newdata = datagrid(vote = levs), vcov = ~country)

court_preds$dv <- "Close Court"
cong_preds$dv <- "Close Congress"

names(court_preds) <- names(cong_preds)
preds <- rbind(cong_preds, court_preds)

ggplot(preds, aes(x = vote, y = estimate, ymin = conf.low, ymax = conf.high, color = dv, fill = dv)) +
  geom_pointrange(position = position_dodge(width = .3)) +
  labs(y = "Proportion Supporting Closure", x = "Party Support", 
       title = "Predicted Support for Closing Congress or the Supreme Court") +
  scale_color_grey(name = "") +
  scale_fill_grey(name = "") + 
  theme_pubclean() +
  theme(legend.position = "right")
  

# Save 
ggsave(
  here("figures/pop_opp_preds.pdf"), 
  height = 6, 
  width = 8)


```




